/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Affichage;

import javax.swing.JFrame;
import Metier.Dialogue;
import Metier.Lieu;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Loick
 */
public class ChangerLieu extends JFrame {

    private javax.swing.JButton BTNValiderCarte;
    private javax.swing.JLabel LBLSelectionnerCarte;
    private javax.swing.JList<String> LSTCartes;
    private javax.swing.JScrollPane jScrollPane1;
    private List<Lieu> c = new ArrayList<>();
    private Vector<String> v;
    private final CustomPanel Panel_Image;

    public ChangerLieu() throws IOException {

        v = new Vector<String>();
        BTNValiderCarte = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        LSTCartes = new javax.swing.JList<String>(v);
        LBLSelectionnerCarte = new javax.swing.JLabel();
        Panel_Image = new CustomPanel("apelosex.jpg");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Changer la carte");
        Dialogue resurl = new Dialogue();
        c = resurl.getUrlEtLibelleLieu();
        for (Lieu lieu : c) {
            v.add(lieu.getLibelle());
        }
        LSTCartes.setListData(v);
        BTNValiderCarte.setText("Changer de carte");
        BTNValiderCarte.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (Lieu lieu : c) {
                    if ((lieu.getLibelle()).equals(LSTCartes.getSelectedValue())) {
                        try {
                            CustomPanel Carte = Affichage.getCarte();
                            //System.out.println(lieu.getCarte());
                            Carte.changeMap(lieu.getCarte());
//                            Affichage affpoi = new Affichage();
//                            affpoi.removeAll();
//                            affpoi.Afficher_POI();
                            dispose();
                        } catch (IOException ex) {
                            Logger.getLogger(ChangerLieu.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
        });



        jScrollPane1.setViewportView(LSTCartes);

        LBLSelectionnerCarte.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        LBLSelectionnerCarte.setText("Veuillez selectionner une carte");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(BTNValiderCarte, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(109, 109, 109))
                .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LBLSelectionnerCarte)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(LBLSelectionnerCarte)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(BTNValiderCarte, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)));

        pack();
    }// </editor-fold>
}